package com.controller;

import com.model.DeliveryAddress;
import com.service.DeliveryAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/elm/DeliveryAddressController")
public class DeliveryAddressController {
    @Autowired
    DeliveryAddressService service;

    @PostMapping("/listDeliveryAddressByUserId")
    public Object listDeliveryAddressByUserId(String userId)throws Exception{
        List<DeliveryAddress> deliveryaddresses = service.listDeliveryAddressByUserId(userId);
        return deliveryaddresses;
    }
    @PostMapping("/getDeliveryAddressById")
    public Object getDeliveryAddressById(int daId)throws Exception{
        DeliveryAddress deliveryAddressById = service.getDeliveryAddressById(daId);
        return deliveryAddressById;
    }
    @PostMapping("/saveDeliveryAddress")
    public Object saveDeliveryAddress(String contactName, String contactTel, String address, int contactSex, String userId)throws Exception{
        int i = service.saveDeliveryAddress(contactName,contactSex,contactTel,address,userId);
        return i;
    }
    @PostMapping("/updateDeliveryAddress")
    public Object updateDeliveryAddress(int daId,String contactName, int contactSex, String contactTel, String address, String userId)throws  Exception{
        int i = service.updateDeliveryAddress(daId,contactName,contactSex,contactTel,address,userId);
        return i;
    }
    @PostMapping("/removeDeliveryAddress")
    public Object removeDeliveryAddress(int daId)throws  Exception{
        int i = service.removeDeliveryAddress(daId);
        return i;
    }
}
